# Copyright 2023 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load(
    "//build_tools/bazel:build_defs.oss.bzl",
    "iree_compiler_cc_library",
    "iree_gentbl_cc_library",
    "iree_tablegen_doc",
)

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_gentbl_cc_library(
    name = "PassesIncGen",
    tbl_outs = [
        (
            ["--gen-pass-decls"],
            "Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "Transforms",
    srcs = [
        "ApplyPDLPatterns.cpp",
        "AttrBasedPipelinePass.cpp",
        "ConvertConv2DToImg2Col.cpp",
        "ConvertConvFilterToChannelsLast.cpp",
        "ConvertConvToChannelsLast.cpp",
        "FoldAttentionWithTranspose.cpp",
        "GeneralizeLinalgMatMul.cpp",
        "InterpreterPass.cpp",
        "MakeSingleDispatchForFunction.cpp",
        "PadLinalgOps.cpp",
        "PadToIntrinsics.cpp",
        "Passes.cpp",
        "SinkTransposeThroughPad.cpp",
        "TransposeMatmul.cpp",
    ],
    hdrs = [
        "Passes.h",
        "Passes.h.inc",
    ],
    deps = [
        ":PassesIncGen",
        "//compiler/src/iree/compiler/Codegen/Common/GPU:GPUHeuristics",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Codegen/Dialect/GPU/IR:IREEGPUDialect",
        "//compiler/src/iree/compiler/Codegen/Utils",
        "//compiler/src/iree/compiler/Dialect/Flow/IR",
        "//compiler/src/iree/compiler/Dialect/Flow/Transforms",
        "//compiler/src/iree/compiler/Dialect/HAL/Analysis",
        "//compiler/src/iree/compiler/Dialect/HAL/IR",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
        "//compiler/src/iree/compiler/Dialect/Stream/Analysis",
        "//compiler/src/iree/compiler/Dialect/Stream/IR",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:Analysis",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:PDLDialect",
        "@llvm-project//mlir:PDLInterpDialect",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TensorUtils",
        "@llvm-project//mlir:TransformDialect",
        "@llvm-project//mlir:TransformDialectTransforms",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
    ],
)

iree_tablegen_doc(
    name = "PreprocessingPassesDocGen",
    category = "Passes",
    tbl_outs = [
        (
            [
                "--gen-pass-doc",
            ],
            "PreprocessingPasses.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)
